package com.wei.czz.framework.game.controller;

import com.wei.czz.common.annotation.Auth;
import com.wei.czz.common.annotation.Resubmit;
import com.wei.czz.common.dto.game.GamePrizeDto;
import com.wei.czz.common.tool.Result;
import com.wei.czz.framework.game.service.LuckDrawService;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wei
 * date: 2023-03-23 16:39:40
 * className: LuckDrawController 抽奖请求接口类
 * version: 1.0
 * description:
 */
@RestController
@RequestMapping("/game")
@AllArgsConstructor
public class LuckDrawController {

    private static final Logger log = LoggerFactory.getLogger(LuckDrawController.class);

    private final LuckDrawService luckDrawService;

    /**
     * 游戏抽奖接口
     * 进行一次游戏抽奖
     * @param gameId 游戏主键
     * @return 抽中的奖品
     */
    @Resubmit(message = "游戏抽奖")
    @GetMapping("/luck/draw")
    @Auth(permit = "game:luck:draw")
    public Result<GamePrizeDto> luckDraw(@RequestParam("gameId") Long gameId) {
        log.info("开始游戏抽奖业务。gameId={}", gameId);

        GamePrizeDto gamePrizeDto = luckDrawService.luckDraw(gameId);

        log.info("游戏抽奖业务结束");
        return Result.success(gamePrizeDto);
    }

}
